const http = require('http');
const route = require('./route.js')

http.createServer((req,res)=>{
    let url = new URL(req.url,'http://localhost');
    res.writeHead(200, {
        'Content-Type': 'text/html;charset=utf8',
        'access-control-allow-origin':'*'
    });
    try{
        route[url.pathname](url,res);
    }catch(e){
        route['/404'](url,res);
    }
    res.end();
}).listen(9999,()=>{
    console.log(`server start`);
})